package com.fm.controller;

import com.fm.entity.Equipment;
import com.fm.entity.TopicLog;
import com.fm.service.EquipmentService;
import com.fm.service.TopicLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLDataException;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/30 0030.
 */
@RestController
@RequestMapping("/api/topicLog")
public class TopicLogController extends MBaseController<TopicLog, TopicLogService>{

    @Autowired
    private EquipmentService equipmentService;

    @Override
    public TopicLog beforeList(Map t) {
        TopicLog topic = new TopicLog();
        topic.setProductId(Integer.parseInt((String) t.get("productId")));
        topic.setOrderBy("createTime desc");
        return topic;
    }


    @Override
    public void afterList(Page<TopicLog> page) {
        for (TopicLog log : page.getContent()) {
            try{
                Equipment equipment = equipmentService.selectOneByExample(log.getEquipmentId()).get();
                log.setEquipmentName(equipment.getName());
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
